package com.atnjupt.controller;

import com.atnjupt.bean.Book;
import com.atnjupt.service.IBookService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//@RestController
@RequestMapping("/books")
public class BookController {
    @Autowired
    IBookService iBookService;

    @GetMapping("/{id}")
    public Book getBookById(@PathVariable("id") Integer id) {
        return iBookService.getById(id);
    }

    @GetMapping
    public List<Book> getAllBooks() {
        List<Book> list = iBookService.list();
        return list;
    }
    @PostMapping
    public Boolean addBook(@RequestBody Book book){
        return iBookService.saveBook(book);
    }
    @PutMapping
    public Boolean updateBook(@RequestBody Book book) {
        return iBookService.modify(book);
    }

    @DeleteMapping("/{id}")
    public Boolean deleteById(@PathVariable("id") Integer id) {
        return iBookService.deleteBookById(id);
    }
    @GetMapping("/{currentPage}/{pageSize}")
    public IPage<Book> getPages(@PathVariable("currentPage") Integer currentPage, @PathVariable("pageSize") Integer pageSize){
        return iBookService.getPage(currentPage, pageSize);
    }
}
